<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('category_id');
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
            $table->string('title')->comment('产品标题');
            $table->string('profile')->nullable()->comment('产品简介');
            $table->text('description')->nullable()->comment('产品描述');
            $table->string('video_url')->nullable()->comment('产品视频链接');
            $table->string('font_image')->nullable()->comment('产品展示图');
            $table->text('carousel_image')->nullable()->comment('产品轮播图');
            $table->boolean('on_sale')->default(true)->comment('是否上架');
            $table->boolean('is_hot')->default(true)->comment('是否热卖');
            $table->boolean('is_new')->default(true)->comment('是否新品');
            $table->boolean('is_recommend')->default(true)->comment('是否推荐商品');
            $table->float('rating')->default(5)->comment('评分');
            $table->unsignedInteger('review_count')->default(0)->comment('评论数');
            $table->unsignedInteger('sort')->default(0)->comment('排序');
            $table->unsignedInteger('sold_count')->default(0)->comment('销量');
            $table->decimal('price', 10, 2)->nullable()->comment('价格');
            $table->unsignedInteger('stock')->nullable()->comment('预设sku库存');
            $table->string('unit')->comment('单位名称');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
